import { modal } from 'vue-strap'
import { showMsg, getPromoterAuditDetail, auditPromoter } from '../../../../vuex/action'

export default {
  name: 'audit-detail',
  props: ['id', 'showModal'],
  data() {
    return {
      status: 2,
      failReason: '',
      otherReason: '',
      selReason: '资料未填写完整',
      detail: {}
    }
  },
  components: {
    modal: modal
  },
  vuex: {
    actions: {
      xShowMsg: showMsg,
      xGetPromoterAuditDetail: getPromoterAuditDetail,
      xAuditPromoter: auditPromoter
    }
  },
  methods: {
    submit() {
      var params = {
        id: this.id + '',
        status: this.status + ''
      }
      if (+this.status === 3) {
        if (this.selReason === '') {
          params.failReason = this.otherReason
        } else {
          params.failReason = this.selReason
        }
      }
      if (params.failReason === '') {
        return this.xShowMsg({
          type: 'danger',
          content: '请填写拒绝理由'
        })
      }
      this.xAuditPromoter(params)
        .then((data) => {
          this.showModal = false
        })
        .catch((res) => {
          this.xShowMsg({
            type: 'danger',
            content: res.error_msg
          })
        })
    },
    openImg() {
      window.open(this.detail.picUrl)
    }
  },
  watch: {
    id() {
      this.xGetPromoterAuditDetail({
        id: this.id
      })
        .then((data) => {
          this.showModal = true
          this.detail = data.detail
        })
        .catch((res) => {
          this.xShowMsg({
            type: 'danger',
            content: res.error_msg
          })
        })
    }
  }
}
